#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

#define DEBUG 0
#define NOISY_TEST 1

int CheckgainCard(int supplyPos, struct gameState *post, int toFlag, int player)
{
  //Note: supplyPos is enum of choosen card
	struct gameState pre;
  memcpy (&pre, post, sizeof(struct gameState));
  int r;
  r= gainCard (supplyPos, post, toFlag, player);

  if (toFlag == 1)
    {
      pre.deck[ player ][ pre.deckCount[player] ] = supplyPos;
      pre.deckCount[player]++;
    }
  else if (toFlag == 2)
    {
      pre.hand[ player ][ pre.handCount[player] ] = supplyPos;
      pre.handCount[player]++;
    }
  else
    {
      pre.discard[player][ pre.discardCount[player] ] = supplyPos;
      pre.discardCount[player]++;
    }
	
  //decrease number in supply pile
  pre.supplyCount[supplyPos]--;
	 
  return 0;
}

int main () {{

  int i, n, r, p, handPos, toFlag, supplyPos;


  struct gameState G;

  printf ("Testing DiscardCard.\n");

  printf ("RANDOM TESTS.\n");

  SelectStream(2);
  PutSeed(3);

  for (n = 0; n < 2000; n++) {
    for (i = 0; i < sizeof(struct gameState); i++) {
      ((char*)&G)[i] = floor(Random() * 256);
    }
    p = floor(Random() * 2);
    G.deckCount[p] = floor(Random() * MAX_DECK);
    G.discardCount[p] = floor(Random() * MAX_DECK);
    G.handCount[p] = floor(Random() * MAX_HAND);
	G.playedCards[p]= floor(Random() * MAX_HAND);
	G.deckCount[p]= floor(Random() * MAX_HAND);
	
    CheckgainCard(supplyPos, &G, toFlag, p);
  }

  printf ("ALL TESTS OK\n");

  exit(0);

  }

  return 0;
}
